﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace _2015.DivAdmin
{
    public partial class DivAdminCalender : System.Web.UI.Page
    {
        int InterviewNo=0;
        String InterviewDate;
        protected void Page_Load(object sender, EventArgs e)
        {
            String Name = (String)Session["CalLoggingInfo"];
            String Position = (String)Session["CalLoggingPosition"];
            String username = (String)Session["CalLoggingInfoUsername"];
            //LabelDivHeadName.Text = Name;
            //LabelPosition.Text = Position;

            //ImageProfile.ImageUrl = "../ProfilePicHandler.ashx?uname=" + username;

            Session["Cal2LoggingInfo"] = Name;
            Session["Cal2LoggingPosition"] = Position;
            Session["Cal2LoggingInfoUsername"] = username;


            if (!IsPostBack)
            {
                Calendar1.Visible = false;
            }
        }



        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            TextBoxDate.Text = Calendar1.SelectedDate.ToShortDateString().ToString();
            Calendar1.Visible = false;

        }

        protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.IsSelected)
            {
                e.Day.IsSelectable = false;
                e.Cell.BackColor = System.Drawing.Color.OrangeRed;
            }

            if (e.Day.IsOtherMonth || e.Day.IsWeekend)
            {
                e.Day.IsSelectable = false;
                e.Cell.BackColor = System.Drawing.Color.Maroon;
            }

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string CS = ConfigurationManager.ConnectionStrings["DBCSFINAL"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("spAddInterview1", con);


                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@INTERVIEWDATE", TextBoxDate.Text);
                cmd.Parameters.AddWithValue("@ROOM_CODE", DropDownListVenue.SelectedValue);
                cmd.Parameters.AddWithValue("@I_STARTS", DropDownListFrom.SelectedValue);
                cmd.Parameters.AddWithValue("@I_ENDS", DropDownListTo.SelectedValue);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

                SqlCommand com3 = new SqlCommand("spGetInterviewNo", con);
                com3.CommandType = CommandType.StoredProcedure;

                SqlParameter sendname1 = new SqlParameter("@INTERVIEWDATE",TextBoxDate.Text);
                com3.Parameters.Add(sendname1);
                SqlParameter sendname2 = new SqlParameter("@ROOM_CODE",DropDownListVenue.SelectedValue);
                com3.Parameters.Add(sendname2);
                SqlParameter sendname3 = new SqlParameter("@I_STARTS",DropDownListFrom.SelectedValue);
                com3.Parameters.Add(sendname3);
                SqlParameter sendname4 = new SqlParameter("@I_ENDS",DropDownListTo.SelectedValue);
                com3.Parameters.Add(sendname4);



                con.Open();
                SqlDataReader dr2;

                dr2 = com3.ExecuteReader();

                if (dr2.Read())
                {
                    InterviewNo = Convert.ToInt32(dr2["INTERVIEW_NO"]);


                }
                InterviewDate = TextBoxDate.Text;
                Session["InterviewNo"] = InterviewNo;
                Session["InterviewDate"] = InterviewDate;
                Session["BoardRoom"] = DropDownListVenue.SelectedValue;

                Response.Redirect("DivAdminCalender2.aspx");
            }
        }

        protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;

            String InterviewDate = Calendar1.SelectedDate.ToString();
        }
    }
}

    
